use serde::{Serialize, Deserialize};
use super::app_config::AppConfig;
use super::site_base::SiteBaseConfig;

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all="camelCase")]
pub struct SiteConfig {
  #[serde(flatten)]
  pub site_base: SiteBaseConfig,
  pub app_list: Vec<AppConfig>,
}

impl SiteConfig {
  pub fn get_target_app(&self, app_name: &str) -> Option<&AppConfig> {
    let target_one = self.app_list.iter().find(|app_config| {
      let target_config = (*app_config).clone();
      return target_config.app_name.eq(app_name);
    });
    return target_one;
  }

  pub fn get_site_directory(&self) -> String {
    self.site_base.get_site_directory()
  }

  pub fn get_site_name(&self) -> &str {
    self.site_base.site_name.as_str()
  }

  pub fn get_url_origin(&self) -> &str {
    self.site_base.url_origin.as_str()
  }
}